package cn.yunhe.servlet;

import cn.yunhe.biz.BoardService;
import cn.yunhe.biz.NewsService;
import cn.yunhe.pojo.Board;
import cn.yunhe.pojo.News;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/ToEditNewsServlet")
public class ToEditNewsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       int newsId= Integer.parseInt(request.getParameter("newsId"));
       String boardname=request.getParameter("boardname");

        BoardService boardService=new BoardService();
        List<Board> boardList=boardService.getAllBoard();

        NewsService newsService=new NewsService();
        News news =newsService.getNewsByNewsId(newsId);
        request.setAttribute("news",news);
        request.setAttribute("boardList",boardList);
        request.setAttribute("boardname",boardname);
        request.getRequestDispatcher("editNews.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
